7250 // init: The initial user-level program
7251 
7252 #include "types.h"
7253 #include "stat.h"
7254 #include "user.h"
7255 #include "fcntl.h"
7256 
7257 char *argv[] = { "sh", 0 };
7258 
7259 int
7260 main(void)
7261 {
7262   int pid, wpid;
7263 
7264   if(open("console", O_RDWR) < 0){
7265     mknod("console", 1, 1);
7266     open("console", O_RDWR);
7267   }
7268   dup(0);  // stdout
7269   dup(0);  // stderr
7270 
7271   for(;;){
7272     printf(1, "init: starting sh\n");
7273     pid = fork();
7274     if(pid < 0){
7275       printf(1, "init: fork failed\n");
7276       exit();
7277     }
7278     if(pid == 0){
7279       exec("sh", argv);
7280       printf(1, "init: exec sh failed\n");
7281       exit();
7282     }
7283     while((wpid=wait()) >= 0 && wpid != pid)
7284       printf(1, "zombie!\n");
7285   }
7286 }
7287 
7288 
7289 
7290 
7291 
7292 
7293 
7294 
7295 
7296 
7297 
7298 
7299 
